package StudyCode.summary.mycollection;

import java.lang.reflect.Array;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GenericMethodToDoArrayClone {
	@SuppressWarnings("unchecked")
	public static <T> T[] arrayClone(T[] array) {
		if (array == null) {
			return array;
		}
		if (array.length == 0) {
			return (T[]) Array.newInstance(array.getClass()
					.getComponentType(), 0);
		}

		T[] clonedArray = (T[]) Array.newInstance(array[0].getClass(),
				array.length);
		System.arraycopy(array, 0, clonedArray, 0, array.length);

		return clonedArray;
	}
}
